package com.yuan.leetcode.JianZhiOffer;

/**
 * Created by yuanhaowu
 * Time 2022/6/10 22:02
 *
 * 看方法二：
 * https://leetcode.cn/problems/er-jin-zhi-zhong-1de-ge-shu-lcof/solution/mian-shi-ti-15-er-jin-zhi-zhong-1de-ge-shu-wei-yun/
 */
public class offer15 {
    public int hammingWeight(int n) {
        int count = 0;
        while(n > 0){
            count++;
            n = n & (n-1);
        }
        return count;
    }
}
